package com.hhq.usercenter.controller;

import com.hhq.common.annotation.ApiLog;
import com.hhq.common.domain.vo.CommonResultVO;
import com.hhq.usercenter.domain.pojo.UserInfo;
import com.hhq.usercenter.domain.req.LoginReq;
import com.hhq.usercenter.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>Description: some description </p>
 *
 * @author : xiaodong.yang
 * @date : 2024/1/8 18:41
 */
@RestController
@RequestMapping("/auth")
@Slf4j
@Api(tags = "登录相关接口")
public class LoginController {


    @Autowired
    private ILoginService loginService;


    /**
     * 登录
     *
     * @param req
     * @return
     */
    @ApiOperation(value = "登录", notes = "登录")
    @PostMapping("/login")
    @ApiLog
    public CommonResultVO<UserInfo> login(@Validated @RequestBody LoginReq req) {

        return CommonResultVO.ok(loginService.login(req));
    }

    /**
     * 注销
     *
     * @return
     */
    @ApiOperation(value = "注销", notes = "注销")
    @GetMapping("/logout")
    @ApiLog
    public CommonResultVO<Void> logout() {
        loginService.logout();
        return CommonResultVO.ok();
    }
}
